import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import Layout from '@/layout/index.vue'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/register/index'),
    meta: { title: '注册', icon: 'el-icon-user-solid' },
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404.vue'),
    hidden: true
  },

  {path: '*', redirect: '/404', hidden: true},

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },


  {
    path: '/Myds',
    component: Layout,
    redirect: '/Myds/user',
    name: 'Myds',
    meta: { title: '用户管理', icon: 'el-icon-s-help' },
    hidden: true,
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/Myds/user.vue'),
        meta: { title: '用户列表', icon: 'tree' }
      },
      {
        path: 'userAddress',
        name: 'UserAddress',
        component: () => import('@/views/Myds/userAddress.vue'),
        meta: { title: '收货地址管理', icon: 'el-icon-s-help'  }
      },
    ]
  },

  {
    path: '/product',
    component: Layout,
    redirect: '/product/findAll',
    name: 'product',
    meta: {title: '商品管理', icon: 'el-icon-s-help'},
    hidden: true,
    children: [
      {
        path: 'findAll',
        name: 'products',
        component: () => import('@/views/product/product.vue'),
        meta: {title: '商品列表', icon: 'tree'}
      },
      {
        path: 'productCategory',
        name: 'ProductCategory',
        component: () => import('@/views/product/productCategory.vue'),
        meta: { title: '商品分类', icon: 'edit' }
      },
      {
        path: 'review',
        name: 'review',
        component: () => import('@/views/product/productReview.vue'),
        meta: { title: '商品评价', icon: 'edit' }
      },
      {
        path: 'stockMgr',
        name: 'StockMgr',
        component: () => import('@/views/tree/stockMgr.vue'),
        meta: {title: '库存管理', icon: 'edit'}
      },
      {
        path: 'echarts',
        name: 'pictureTable',
        component: () => import('@/views/product/pictureTable.vue'),
        meta: {title: '商品报表', icon: 'edit'}
      },
    ]
  },

  {
    path: '/order',
    component: Layout,
    redirect: '/order/orderList',
    name: 'Order',
    meta: {title: '订单管理', icon: 'el-icon-s-help'},
    hidden: true,
    children: [
      {
        path: 'orderListV2',
        name: 'OrderListV2',
        component: () => import('@/views/order/orderListV2.vue'),
        meta: {title: '订单列表', icon: 'el-icon-s-order'}
      },

      {
        path: '/order/OrderItem',
        name: 'OrderItem',
        component: () => import('@/views/order/orderDetail.vue'),
        meta: {title: '订单详情', icon: 'el-icon-s-order'},
      },

      {
        path: 'refundManageV2',
        name: 'RefundManageV2',
        component: () => import('@/views/order/refundManageV2.vue'),
        meta: {title: '订单退款管理', icon: 'el-icon-s-data'}
      },
      {
        path: 'orderStatistics',
        name: 'OrderStatistics',
        component: () => import('@/views/order/orderStatistics.vue'),
        meta: {title: '订单统计', icon: 'el-icon-s-data'}
      },
      {
        path: '/refund/refundDetail',
        name: 'RefundDetail',
        component: () => import('@/views/order/refundDetail.vue'),
        meta: {title: '订单退款详情', icon: 'el-icon-s-data'},
        hidden: true
      },
    ]
  },


  {
    path: '/attendance',
    component: Layout,
    redirect: '/attendance/AttendanceRecords',
    children: [{
      path: 'AttendanceRecords',
      name: 'attendanceRecords',
      component: () => import('@/views/attendanceRecords/index.vue'),
      meta: {title: '考勤管理', icon: 'tree'}
    }]
  },


]
const createRouter = () => new Router({
          // mode: 'history', // require service support
          scrollBehavior: () => ({ y: 0 }),
          routes: constantRoutes
        })
const router = createRouter()

    // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
          const newRouter = createRouter()
          router.matcher = newRouter.matcher // reset router
        }
export default router
